/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.sql.*;
import javax.servlet.http.HttpSession;

/**
 *
 * @author lion
 */
public class MysqlHelper {

    private Connection conn = null;
    private Statement stm = null;
    
    public Connection GetConnection() throws Exception {
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        return DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/fastlearndatabase", "root", "abc@123");
    }

    public ResultSet ExecuteReader(String query) throws Exception{
        conn = GetConnection();
        stm = conn.createStatement();
        return stm.executeQuery(query);
    }

    public int ExecuteUpdate(String query) throws Exception{
        conn = GetConnection();
        stm = conn.createStatement();
        return stm.executeUpdate(query);
    }
    
    public void Close() throws Exception{
        conn = GetConnection();
        if (!conn.isClosed()) {
            conn.close();
        }
    }
}
